package com.linkoog.devtools.http.request.http_response.response;

import com.intellij.openapi.Disposable;
import com.intellij.openapi.project.Project;
import com.intellij.ui.Gray;
import com.intellij.ui.JBColor;
import com.intellij.ui.tabs.TabInfo;
import com.intellij.ui.tabs.impl.JBEditorTabs;
import com.intellij.util.ui.JBUI;
import com.linkoog.devtools.http.request.common.HttpResponse;
import com.linkoog.devtools.http.request.http_response.response.response_body.ResponseBodyPanel;
import com.linkoog.devtools.http.request.http_response.response.response_header.ResponseHeaderPanel;

import javax.swing.*;
import java.awt.*;

public class ResponsePanel extends JPanel implements Disposable {

    private Project project;

    private JBEditorTabs editorTabs;

    private ResponseBodyPanel responseBodyPanel;
    private TabInfo bodyTabInfo;
    private ResponseHeaderPanel responseHeaderPanel;
    private TabInfo headerTabInfo;

    public ResponsePanel(Project project) {
        super(new BorderLayout());
        this.project = project;
        this.editorTabs = new JBEditorTabs(project, this);
        this.add(editorTabs, BorderLayout.CENTER);
        this.setBorder(JBUI.Borders.customLineRight(new JBColor(Gray._214, new Color(30, 31, 34))));

        initResponseBodyPanel(project);
        initResponseHeaderPanel(project);
    }

    public void reset(HttpResponse httpResponse) {
        responseBodyPanel.reset(httpResponse.getResponseBody());
        responseHeaderPanel.reset(httpResponse.getHeaders());
    }


    private void initResponseBodyPanel(Project project) {
        responseBodyPanel = new ResponseBodyPanel(project);
        bodyTabInfo = new TabInfo(responseBodyPanel);
        bodyTabInfo.setText("Body");
        bodyTabInfo.setObject("Body");
        editorTabs.addTab(bodyTabInfo);
    }

    private void initResponseHeaderPanel(Project project) {
        responseHeaderPanel = new ResponseHeaderPanel();
        headerTabInfo = new TabInfo(responseHeaderPanel);
        headerTabInfo.setText("Headers");
        headerTabInfo.setObject("Headers");
        editorTabs.addTab(headerTabInfo);
    }

    @Override
    public void dispose() {

    }
}
